#include<bits/stdc++.h>
using namespace std;
inline void read(int &n)
{
    int x=0,f=1;
    char ch;
    for(ch=getchar();!(ch>='0'&&ch<='9')&&ch!='-';ch=getchar());
    if(ch=='-')
    {
        f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+ch-'0';
        ch=getchar();
    }
    n=x*f;
}
const int N=1e5+5;
int T;
int n,m,L,V,ans1=0,ans2=0;
int d[N],v[N],a[N],p[N];
priority_queue<pair<int,int> > q;
void clear()
{
    while(!q.empty()) q.pop();
}
void solution1()
{
    // vector<int> k[N],g[N];
    // int s[N];
    // memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++)
    {
        int f=1;
        if(a[i]>=0)
        {
            for(int j=1;j<=m;j++)
            {
                if(p[j]<d[i])
                {
                    continue;
                }
                if(2*a[i]*(p[j]-d[i])+v[i]*v[i]>V*V)
                {
                    ans1+=f;
                    f=0;
                    break;
                }
            }
        }
        if(a[i]<0)
        {
            for(int j=1;j<=m;j++)
            {
                if(p[j]<d[i])
                {
                    continue;
                }
                if(2*a[i]*(p[j]-d[i])+v[i]*v[i]<0) break;
                else
                {
                    if(2*a[i]*(p[j]-d[i])+v[i]*v[i]>V*V)
                    {
                        ans1+=f;
                        ans2+=f;
                        f=0;
                        // k[i].push_back(j);
                        // g[j].push_back(i);
                        // s[j]++;
                    }
                    else break;
                }
            }
        }
    }
    // for(int i=1;i<=m;i++)
    // {
    //     pair<int,int> pi;
    //     pi.first=s[i];
    //     pi.second=i;
    //     q.push(pi);
    // }
    cout<<ans1<<" "<<m-ans2-1<<endl;
}
void solutionA()
{
    int maxp=p[m];
    for(int i=1;i<=n;i++)
    {
        if(d[i]<=maxp)
        {
            if(v[i]>V) ans1++;
        }
    }
    ans2=m-1;
    if(ans1) cout<<ans1<<" "<<ans2<<endl;
    else cout<<0<<" "<<m<<endl;
}
void solutionB()
{
    int maxp=p[m];
    for(int i=1;i<=n;i++)
    {
        if(d[i]<=maxp)
        {
            if(2*a[i]*(maxp-d[i])+v[i]*v[i]>V*V) ans1++;
        }
    }
    ans2=m-1;
    if(ans1) cout<<ans1<<" "<<ans2<<endl;
    else cout<<0<<" "<<m<<endl;
}
void solutionC()
{
    // vector<int> k[N],g[N];
    // int s[N];
    // memset(s,0,sizeof(s));
    for(int i=1;i<=n;i++)
    {
        int f=1;
        if(a[i]>=0)
        {
            for(int j=1;j<=m;j++)
            {
                if(p[j]<d[i])
                {
                    continue;
                }
                if(2*a[i]*(p[j]-d[i])+v[i]*v[i]>V*V)
                {
                    ans1+=f;
                    f=0;
                    break;
                }
            }
        }
        if(a[i]<0)
        {
            for(int j=1;j<=m;j++)
            {
                if(p[j]<d[i])
                {
                    continue;
                }
                if(2*a[i]*(p[j]-d[i])+v[i]*v[i]<0) break;
                else
                {
                    if(2*a[i]*(p[j]-d[i])+v[i]*v[i]>V*V)
                    {
                        ans1+=f;
                        ans2+=f;
                        f=0;
                        // k[i].push_back(j);
                        // g[j].push_back(i);
                        // s[j]++;
                    }
                    else break;
                }
            }
        }
    }
    // for(int i=1;i<=m;i++)
    // {
    //     pair<int,int> pi;
    //     pi.first=s[i];
    //     pi.second=i;
    //     q.push(pi);
    // }
    cout<<ans1<<" "<<m-ans2-1<<endl;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    read(T);
    while(T--)
    {
        ans1=0;
        ans2=0;
        // clear();
        read(n);read(m);read(L);read(V);
        bool f1=true,f2=true,f3=true;
        for(int i=1;i<=n;i++)
        {
            read(d[i]);read(v[i]);read(a[i]);
            if(a[i]) f1=false;
            if(a[i]<=0) f2=false;
            if(a[i]>=0) f3=false;
        }
        for(int i=1;i<=m;i++)
        {
            read(p[i]);
        }
        if(f1) solutionA();
        else
        {
            if(f2) solutionB();
            else
            {
                if(n<=3000) solution1();
                else if(f3) solutionC();
                else solution1();
            }
        }
    }
    return 0;
}